package com.neusoft.demo7;

public class B extends A {
    int x = 2;
    @Override
    public void fun() {
        System.out.println("sub......");
    }

    public static void main(String[] args) {
        B b = new B();
        b.fun(); //sub......
        System.out.println(b.x);//2

        A a = new A();
        a.fun();
        System.out.println(a.x);

        A x = new B(); //父类的引用指向子类的对象
        x.fun();
        System.out.println(x.x);

    }
}
